package com.zzh.takeoutapp.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zzh.takeoutapp.R;
import com.zzh.takeoutapp.adapter.CacheFragmentStatePagerAdapter;
import com.zzh.takeoutapp.base.BaseFragment;
import com.zzh.takeoutapp.service.ServiceUrl;
import com.zzh.takeoutapp.utils.ColorUtil;
import com.zzh.takeoutapp.view.goods.ViewUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/7/11.
 */

public class OrderFragment extends BaseFragment {

    @Bind(R.id.tablayout)
    TabLayout mTabLayout;
    @Bind(R.id.viewpager)
    ViewPager mVPager;
    public NavigationAdapter adapter;
    public List<String> stringList;

    @Override
    public void getsavedInstanceState(Bundle savedInstanceState) {

    }

    public static OrderFragment newInstance() {
        OrderFragment fragment = new OrderFragment();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container) {
        View mView = inflater.inflate(R.layout.fragment_order, null);
        ButterKnife.bind(this, mView);
        return mView;
    }

    private class NavigationAdapter extends CacheFragmentStatePagerAdapter {
        List<String> type;

        public NavigationAdapter(FragmentManager fm, List<String> type) {
            super(fm);
            this.type = type;
        }

        @Override
        protected OrderListFragment createItem(int position) {
            return OrderListFragment.newInstance(position);
        }

        @Override
        public int getCount() {
            return type.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return type.get(position);
        }


    }

    @Override
    public void initComponent(View view) {
        stringList = new ArrayList<>();
        stringList.add("全部订单");
        stringList.add("待付款");
        stringList.add("已支付");
        stringList.add("退款");
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        ColorUtil.reflex(mTabLayout);
        mTabLayout.setTabTextColors(getResources().getColor(R.color.black_divider),
                getResources().getColor(R.color.yellow));
        mTabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.yellow));
        mTabLayout.setSelectedTabIndicatorHeight(5);
        mVPager.setOffscreenPageLimit(4);
        adapter = new NavigationAdapter(getChildFragmentManager(), stringList);
        mVPager.setAdapter(adapter);
        mTabLayout.setupWithViewPager(mVPager);
    }


    @Override
    public void setListener() {
    }

    @Override
    public void onAfterInit() {

    }


    @Override
    public void onClick(View view) {

    }
}
